<?
class ServiceController extends BaseController{
    var $table = 'products';
    var $id_field = 'pro_id';
    var $name_field = 'pro_name';
    var $thumb_field = 'pro_thumb';
    var $slide_field = 'pro_slide';
    var $record_id;
    var $type;
    var $type_string;
    var $type_name;

    public function __construct($id){
        parent::__construct($id);
        //Xác định type service
        $pro_cat_id = $this->get('pro_cat_id');
        $parent_cat_id_db = new db_query('SELECT cat_name,cat_id,cat_parent_id FROM categories_multi WHERE cat_id = '.$pro_cat_id);
        $parent_cat_id_res = mysql_fetch_assoc($parent_cat_id_db->result);
        $parent_cat_id = $parent_cat_id_res['cat_parent_id'];
        global $global_category_config;
        foreach($global_category_config as $type => $cat_id){
            if($parent_cat_id == $cat_id){
                $this->type = $type;
                if($this->type == 'serviceSoftID'){
                    $this->type_string = 'dich-vu-phan-mem';
                    $this->type_name = 'Dịch vụ phần mềm';
                }
                if($this->type == 'serviceHardID'){
                    $this->type_name = 'Dịch vụ phần cứng';
                    $this->type_string = 'dich-vu-phan-cung';
                }
                break;
            }
        }
        $seo_mt = showSeoMeta('products',$id);
            if($seo_mt != '') {
                $im_seo = $seo_mt;
            }else {
                $im_seo = '<title>'. $this->get('pro_name') .'</title>';
                $im_seo .= '<meta name="description" content="'. $this->get('pro_basic_info') .'"/>';
        }
        $this->seo_string = ''.$im_seo.'
	                         <meta property="og:image" content="http://fonecare.vn/pictures/products/' . $this->get('pro_thumb') . '" />
                        	 <meta property="og:type" content="products" />
                        	 <meta property="og:title" content="' . $this->get('pro_name') . '" />
                        	 <meta property="fb:app_id" content="524593015322765" />
                        	 <meta property="fb:admins" content="100000472324543" />';
    }
    public function get($field_name){
        return $this->getDataField($field_name);
    }
    public function GetBreadcrumb(){
        $attribute = array(
            'service'=>'Dịch vụ',
            'service_url'=>'#',
            'sub_service'=>$this->type_name,
            'sub_service_url'=>generate_service_cat($this->type_string),
            'detail_service'=>$this->get('pro_name'),
            'detail_service_url'=>generate_service_detail_url(array('pro_id'=>$this->record_id,'pro_name'=>$this->get('pro_name')))
        );
        return ServiceLayout::generate_detail_breadcrumb($attribute);
    }
    public function GetProductThumb(){
        return PATH_PICTURE_PRODUCT . $this->GetThumb();
    }

    /*
     * Lấy các sản phẩm liên quan
     */
    public function getProductRelation(){
        global $global_product_status_in_stock;
        $pro_relate = $this->get('pro_relate');
        if(!$pro_relate){
            return '';
        }
        $pro_array = array();
        $db_query = new db_query('SELECT pro_id, pro_name,pro_thumb,pro_price,pro_status_in_stock,pro_number_in_stock
                                  FROM products
                                  WHERE pro_id IN('.$pro_relate.')');
        while($row = mysql_fetch_assoc($db_query->result)){
            $tmp = array(
                'thumb'=> PATH_PICTURE_PRODUCT . $row['pro_thumb'],
                'name'=> $row['pro_name'],
                'price'=> format_price($row['pro_price']),
                'link'=> generate_product_detail_url($row),
                'status'=> $global_product_status_in_stock[$row['pro_status_in_stock']]
            );
            $pro_array[] = $tmp;
        }
        return ProductLayout::product_relate_detail($pro_array);
    }
}
?>